{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--BOOK_INFORMATION-->\n",
    "<img align=\"left\" style=\"padding-right:10px;\" src=\"figures/PHydro-cover-small.png\">\n",
    "*This is the Jupyter notebook version of the [Python in Hydrology](http://www.greenteapress.com/pythonhydro/pythonhydro.html) by Sat Kumar Tomer.*\n",
    "*Source code is available at [code.google.com](https://code.google.com/archive/p/python-in-hydrology/source).*\n",
    "\n",
    "*The book is available under the [GNU Free Documentation License](http://www.gnu.org/copyleft/fdl.html). If you have comments, corrections or suggestions, please send email to satkumartomer@gmail.com.*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--NAVIGATION-->\n",
    "< [Linear Regression](05.07-Linear-Regression.ipynb) | [Contents](Index.ipynb) | [Interpolation](05.09-Interpolation.ipynb) >"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5.8 多项式回归\n",
    "\n",
    "我们可以使用`np.polyfit`进行多项式回归。这提供了拟合系数。我们可以将多项式的阶次定义为`np.polyfit`函数的第三个参数。首先，我们生成一个二次多项式($y=1+2x-3x^2$)，然后我们为它添加噪音。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-3.34229752  5.19630246 -4.85795351]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "# 生成数据\n",
    "x = np.linspace(0,10)\n",
    "y = 1 + 2*x - 3*x**2 + 15*np.random.randn(50)\n",
    "# 拟合多项式\n",
    "z = np.polyfit(x,y,2)\n",
    "print(z)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`np.polyfit`函数提供的拟合多项式为$y=4.58+1.34-3.03x^2$,然而真实的多项式系数是不一样的。只有第三个参数是合理计算的。其他两个参数与真实参数相差很远。让我们看看拟合多项式与真实的多项式相比的行为。`np.polyld`函数是用`np.polyfit`返回的拟合系数来评估多项式。图5.14显示了结果图。虽然拟合的系数与真实的系数不同，但拟合的多项式与真实的多项式比较接近。与第二级相关的参数是由`np.polyfit`相当合理的计算，这意味着这是与其他参数相比最敏感的参数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZEAAAEKCAYAAADTgGjXAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAIABJREFUeJzt3Xd4VNXWwOHfmkkloYReQglNaaGFQEAEBASUYgGlKEVBwGtFLKjYUPHaRRFEioIoTSk2BETKJ02QIk3pEnoJkED67O+PGXIDpJNpyXqfO8/M7DllncidNbucvcUYg1JKKZUXFncHoJRSyntpElFKKZVnmkSUUkrlmSYRpZRSeaZJRCmlVJ5pElFKKZVnmkSUUkrlmSYRpZRSeaZJRCmlVJ75uDsAZytdurSpVq2au8NQSimvsWnTptPGmDI52bbAJ5Fq1aqxceNGd4ehlFJeQ0QO5XRbbc5SSimVZ5pElFJK5ZkmEaWUUnlW4PtElFKeLTk5mejoaBISEtwdSqETEBBAaGgovr6+eT6GJhGllFtFR0dTtGhRqlWrhoi4O5xCwxjDmTNniI6OJiwsLM/H0eYspZRbJSQkUKpUKU0gLiYilCpV6rprgJpEvMnatTB2rP1ZqQJEE4h75MffXZuz3GntWlixAtq2haio7Ldt3x6SksDPD379Nft9lFLKybQm4i6Xk8Lo0fbn7GoXK1bYE0hqqv15xQpXRKmUysBLL73EsmXL8vWYwcHBWX5+7tw5Pv3003w9Z37QJJJfctvUlNuk0LatvQZitdqf27a9vniVUnn22muv0aFDB5eeU5NIQZZVrSKz5JLbpBAVZW/CGjNGm7KUysf+wYMHD1KnTh2GDBlCvXr1uPXWW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RSimVZ5pElFJK5ZkmEaWUUnmmSUQppVSeaRJRSimVZ/8PPWfWcAPMd4wAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a8a5a5fc50>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "# evaluate polynomial\n",
    "p = np.poly1d(z)\n",
    "z_true = np.array([-3, 2, 1]) # coefficient of true polynomial\n",
    "p_true = np.poly1d(z_true) # true polynomial\n",
    "# plot\n",
    "plt.plot(x, y,'.r', label='noisy data')\n",
    "plt.plot(x, p_true(x), label='True curve')\n",
    "plt.plot(x, p(x), label='Fitted curve')\n",
    "plt.xlabel('x')\n",
    "plt.ylabel('y')\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
